package com.dongdongshop.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.core.Result;
import com.dongdongshop.core.ResultEnum;
import com.dongdongshop.pojo.TbSeller;
import com.dongdongshop.service.SellerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("sellerController")
public class SellerController {
    //开启日志
    Logger logger = LoggerFactory.getLogger(TemplateController.class);

    @Reference(check=false ,timeout=106666)
    private SellerService sellerService;

    //商家审核页面
    @RequestMapping("sellerShList")
    public java.lang.String sellerShList(){
        return "admin/seller_1";
    }
    //商家展示页面
    @RequestMapping("sellerShowList")
    public String sellerShowList(){
        return "admin/seller";
    }
    //商家审核
    @RequestMapping("getSeller")
    @ResponseBody
    public Result getSeller(String name,String nickName){
        try {
            logger.info("查询方法开始运行{}");
            List<TbSeller> sellers = sellerService.getSeller(name,nickName);
            return Result.response(ResultEnum.SUCCESS).setData(sellers);
        }catch (Exception e){
            Result.response(ResultEnum.ERROR);
            logger.error("出现错误，查看日志{}",e);
        }
        return Result.response(ResultEnum.SUCCESS);
    }

    @RequestMapping("getSellerById")
    @ResponseBody
    public Result getSellerById(String sellerId){
        try {
            logger.info("详情方法开始运行{}");
            TbSeller sellers = sellerService.getSellerById(sellerId);
            return Result.response(ResultEnum.SUCCESS).setData(sellers);
        }catch (Exception e){
            Result.response(ResultEnum.ERROR);
            logger.error("出现错误，查看日志{}",e);
        }
        return Result.response(ResultEnum.SUCCESS);
    }
    @RequestMapping("approved")
    @ResponseBody
    public Result approved(TbSeller seller){
        try {
            logger.info("审核通过方法开始运行{}");
            sellerService.approved(seller);
        }catch (Exception e){
            Result.response(ResultEnum.ERROR);
            logger.error("出现错误，查看日志{}",e);
        }
        return Result.response(ResultEnum.SUCCESS);
    }
    @RequestMapping("auditfailed")
    @ResponseBody
    public Result auditfailed(TbSeller seller){
        try {
            logger.info("审核不通过方法开始运行{}");
            sellerService.auditfailed(seller);
        }catch (Exception e){
            Result.response(ResultEnum.ERROR);
            logger.error("出现错误，查看日志{}",e);
        }
        return Result.response(ResultEnum.SUCCESS);
    }
    @RequestMapping("closeSeller")
    @ResponseBody
    public Result closeSeller(TbSeller seller){
        try {
            logger.info("关闭商家方法开始运行{}");
            sellerService.closeSeller(seller);
        }catch (Exception e){
            Result.response(ResultEnum.ERROR);
            logger.error("出现错误，查看日志{}",e);
        }
        return Result.response(ResultEnum.SUCCESS);
    }

    //商家管理
    @RequestMapping("getAllSeller")
    @ResponseBody
    public Result getAllSeller(String name,String nickName,String status){
        try {
            logger.info("查询方法开始运行{}");
            List<TbSeller> sellers = sellerService.getAllSeller(name,nickName,status);
            return Result.response(ResultEnum.SUCCESS).setData(sellers);
        }catch (Exception e){
            Result.response(ResultEnum.ERROR);
            logger.error("出现错误，查看日志{}",e);
        }
        return Result.response(ResultEnum.SUCCESS);
    }
}
